<?php

namespace app\merchants\services;

use app\common\loader\ModelMerchant;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;


/**
 * 积分商品分类
 */
class MerchantProductPointClassService extends BaseService
{

    /**
     * 分类列表
     * @param array $option
     * @param int $limit
     * @return array|null
     * @throws DbException
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     */
    public function getList(array $option, int $limit = 10): ?array
    {
        return ModelMerchant::MerchantProductPointClass()->classList($option,$limit);
    }

    /**
     * 分类：增加，修改
     * @param $data
     * @param int $id
     * @return int
     * @throws DbException|Exception
     */
    public function save($data, int $id = 0): int
    {
        return ModelMerchant::MerchantProductPointClass()->save($data, $id);
    }


    /**
     * 删除
     * @param int $id
     * @return bool
     * @throws DbException|Exception
     */
    public function del(int $id, $mer_id): bool
    {
        return ModelMerchant::MerchantProductPointClass()->del($id, $mer_id);
    }

    /**
     * 详情
     * @param int $id
     */
    public function info(int $id)
    {
        return ModelMerchant::MerchantProductPointClass()->info($id);
    }

    /**
     * 修改排序
     * @param int $id
     * @param int $sort
     * @return int|string
     * @throws DbException
     */
    public function save_sort(int $id, int $sort)
    {
        return ModelMerchant::MerchantProductPointClass()->where('id', $id)
            ->update(null, ['sort' => $sort]);
    }

}
